CC=gcc
CXX=g++
CFLAGS=-Wall $(DEBUG) $(DEFINITIONS) $(CINCLUDES) $(CMISCFLAGS) $(CE)
CPPFLAGS=-Wall $(DEBUG) $(CPPINCLUDES) $(DEFINITIONS) $(CPPMISCFLAGS) $(CE)
DEBUG=-O0 -g3
CMISCFLAGS=
CPPMISCFLAGS=
DEFINITIONS=-DLINUX_OS
CINCLUDES=-I. -I$(GDIR)/tcpHub -I$(GDIR)/utils -I$(GDIR)/bitestream
CPPINCLUDES=-I. `xml2-config --cflags` -I$(GDIR)/GIMI -I$(GDIR)/GIMI/datatypes \
$(INCGIMI) \
$(MACI_INCLUDE_PATHS) \
$(MACI_INTERFACE_IMAGE_EXT_INCLUDE) \
`pkg-config --cflags opencv`


LD=g++
LDFLAGS=
LIBS= -lrt -lpthread -lGL -lGLU -lglut `pkg-config --libs opencv`  `xml2-config --libs` \
$(MACI_INTERFACE_IMAGE_EXT_LIBS)
GDIR=../..
MACIPATH=$(GDIR)/MaCI
SRCSC=$(GDIR)/utils/imageutils.c $(MACI_INTERFACE_IMAGE_EXT_C)
SRCSCPP=OpenCVStereoCalibrator.cpp \
$(GDIR)/utils/binbag.cpp \
$(MACI_BASE_SRC_CPP) \

VPATH=
CPPGIMI=
CGIMI=

## Build GIMI and it's dependencies.
## Files are set to CGIMI and CPPGIMI variables
include $(GDIR)/GIMI/Makefile.gimi

## Include MaCI-stuff
include $(MACIPATH)/interfaces/MaCI-interfaces.Makefile

## Construct final lists of CPP and C objects
OBJS_C=$(SRCSC:.c=.o)
OBJS_CPP=$(SRCSCPP:.cpp=.opp)
OBJSC=$(CGIMI:.c=.o)
OBJSCPP=$(CPPGIMI:.cpp=.opp)

## Define compiles and links
COMPILEC=$(CC) $(CFLAGS) $(CINCLUDES) -c
COMPILECPP=$(CXX) $(CPPFLAGS) $(CPPINCLUDES) -c
LINK=$(LD) $(LDFLAGS) $(LIBS)

.PHONY: all clean

all: OpenCVStereoCalibrator

OpenCVStereoCalibrator: $(OBJSC) $(OBJSCPP) $(OBJS_C) $(OBJS_CPP)
	@$(LINK) -o $@ $(OBJSC) $(OBJSCPP) $(OBJS_C) $(OBJS_CPP)
	@echo "      [LD] $@"

clean:
	rm -f $(OBJS_C) $(OBJS_CPP) Gimbo *.out *~ *.d *.dpp

realclean: clean
	rm -f $(OBJSC) $(OBJSCPP) *.out *~ *.d *.dpp

## Below this is dependency generation stuff, no need to change.
## Compile rule for all .o (.c) file
%.o:    %.c
	@$(COMPILEC) -o $@ $<
	@echo "      [CC] $<"

## Compile rule for all .opp (.cpp) files
%.opp:  %.cpp
	@$(COMPILECPP) -o $@ $<
	@echo "      [CXX] $<"
